<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Deciding to Defer</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Deciding to Defer' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">imperative</a></li><li><a href="index.html#4">Chapter 4: Propositions</a></li><li><b>Deciding to Defer</b></li></ul></div>
<p class="purpose">To decide whether a proposition can be compiled immediately, in the body of the current function, or whether it must be deferred to a function of its own, which is merely called from the current function.</p>

<ul class="toc"><li><a href="4-dtd.html#SP1">&#167;1. Reasons for deferral</a></li><li><a href="4-dtd.html#SP2">&#167;2. Deferral requests</a></li><li><a href="4-dtd.html#SP4">&#167;4. Testing, or deferring a test</a></li><li><a href="4-dtd.html#SP10">&#167;10. Forcing with now, or deferring the force</a></li><li><a href="4-dtd.html#SP11">&#167;11. Other uses</a></li><li><a href="4-dtd.html#SP12">&#167;12. Multipurpose descriptions</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Reasons for deferral.</b>There are a number of possible reasons to defer a proposition, depending on
how it is to be used; we may even want to convert a proposition to a
"multipurpose" deferral function, capable of doing any of these on demand
at runtime.
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">CONDITION_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">       </span><span class="comment-syntax"> "if S", where S is a sentence</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">NOW_ASSERTION_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">   </span><span class="comment-syntax"> "now S"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">EXTREMAL_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax">        </span><span class="comment-syntax"> "the heaviest X", where X is a description</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">LOOP_DOMAIN_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax">     </span><span class="comment-syntax"> "repeat with I running through X"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">NUMBER_OF_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">5</span><span class="plain-syntax">       </span><span class="comment-syntax"> "the number of X"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TOTAL_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">6</span><span class="plain-syntax">           </span><span class="comment-syntax"> "the total P of X"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TOTAL_REAL_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">7</span><span class="plain-syntax">      </span><span class="comment-syntax"> "the total P of X"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">RANDOM_OF_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">8</span><span class="plain-syntax">       </span><span class="comment-syntax"> "a random X"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">LIST_OF_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">9</span><span class="plain-syntax">         </span><span class="comment-syntax"> "the list of X"</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">MULTIPURPOSE_DEFER</span><span class="plain-syntax"> </span><span class="constant-syntax">100</span><span class="plain-syntax">  </span><span class="comment-syntax"> potentially any of the above</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">MAX_CINDERS_PER_DEFERRAL</span><span class="plain-syntax"> </span><span class="constant-syntax">16</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">reason</span><span class="plain-syntax">; </span><span class="comment-syntax"> what we intend to do with it: one of the </span><span class="extract"><span class="extract-syntax">*_DEFER</span></span><span class="comment-syntax"> values above</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">proposition_to_defer</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">deferred_from</span><span class="plain-syntax">; </span><span class="comment-syntax"> remember where it came from, for Problem reports</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">defn_ref</span><span class="plain-syntax">; </span><span class="comment-syntax"> sometimes we must remember other things too</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cinder_kinds</span><span class="plain-syntax">[</span><span class="constant-syntax">MAX_CINDERS_PER_DEFERRAL</span><span class="plain-syntax">]; </span><span class="comment-syntax"> the kinds of value being cindered (see below)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ppd_iname</span><span class="plain-syntax">; </span><span class="comment-syntax"> function to implement this</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">rtp_iname</span><span class="plain-syntax">; </span><span class="comment-syntax"> compile a string of the origin text for run-time problems?</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>The structure pcalc_prop_deferral is accessed in 4/cl, 4/cad, 4/cdp and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Deferral requests.</b>The following fills out the paperwork to request a deferred proposition.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="function-syntax">Deferrals::new</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">Deferrals::new</span></span>:<br/><a href="4-dtd.html#SP3">&#167;3</a>, <a href="4-dtd.html#SP4">&#167;4</a>, <a href="4-dtd.html#SP9">&#167;9</a>, <a href="4-dtd.html#SP10">&#167;10</a>, <a href="4-dtd.html#SP11">&#167;11</a>, <a href="4-dtd.html#SP13">&#167;13</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">reason</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">proposition_to_defer</span><span class="plain-syntax"> = </span><span class="identifier-syntax">prop</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">reason</span><span class="plain-syntax"> = </span><span class="identifier-syntax">reason</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">deferred_from</span><span class="plain-syntax"> = </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">rtp_iname</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ppd_iname</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Enclosures::new_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">PROPOSITIONS_HAP</span><span class="plain-syntax">, </span><span class="identifier-syntax">PROPOSITION_HL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">desc</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">desc</span><span class="plain-syntax">, </span><span class="string-syntax">"deferred proposition (reason %d) for "</span><span class="plain-syntax">, </span><span class="identifier-syntax">reason</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Propositions::write</span><span class="plain-syntax">(</span><span class="identifier-syntax">desc</span><span class="plain-syntax">, </span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Sequence::queue</span><span class="plain-syntax">(&amp;</span><a href="4-cdp.html#SP2" class="function-link"><span class="function-syntax">DeferredPropositions::compilation_agent</span></a><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">STORE_POINTER_pcalc_prop_deferral</span><span class="plain-syntax">(</span><span class="identifier-syntax">pdef</span><span class="plain-syntax">), </span><span class="identifier-syntax">desc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>We cache deferral requests in the case of loop domains, because they are typically
needed in the case of repeat-through loops where the same proposition is used three
times in a row.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cache_loop_proposition</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">cache_loop_pdef</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="function-syntax">Deferrals::defer_loop_domain</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_loop_domain</span></span>:<br/>Compile Loops - <a href="4-cl.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> == </span><span class="identifier-syntax">cache_loop_proposition</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">cache_loop_pdef</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP2" class="function-link"><span class="function-syntax">Deferrals::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">LOOP_DOMAIN_DEFER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cache_loop_proposition</span><span class="plain-syntax"> = </span><span class="identifier-syntax">prop</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cache_loop_pdef</span><span class="plain-syntax"> = </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Testing, or deferring a test.</b>This is the first of several functions serving <a href="4-cp.html" class="internal">Compile Propositions</a>. In
each case we decide whether or not to defer: if so we return <span class="extract"><span class="extract-syntax">TRUE</span></span> and compile
the necessary code to call the deferred function; and if not return <span class="extract"><span class="extract-syntax">FALSE</span></span> and
do nothing. (If we issue a problem message, we should then return <span class="extract"><span class="extract-syntax">TRUE</span></span>.)
</p>

<p class="commentary">We defer the proposition to a test function of its own if and only if it contains
quantification. The test function returns the verdict <span class="extract"><span class="extract-syntax">true</span></span> or <span class="extract"><span class="extract-syntax">false</span></span>, so to
evaluate the condition we just need to call it.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_test_of_proposition</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_test_of_proposition</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">substitution</span><span class="plain-syntax">, </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Propositions::contains_quantifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><a href="2-cc.html#SP3" class="function-link"><span class="function-syntax">CompileConditions::begin</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">go_up</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="4-dtd.html#SP4_1" class="named-paragraph-link"><span class="named-paragraph">If the proposition is a negation, take care of that now</span><span class="named-paragraph-number">4.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">NC</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP6" class="function-link"><span class="function-syntax">Deferrals::count_callings_in_condition</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NC</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">AND_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP2" class="function-link"><span class="function-syntax">Deferrals::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">CONDITION_DEFER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="4-dtd.html#SP4_2" class="named-paragraph-link"><span class="named-paragraph">Compile the call to the deferred function</span><span class="named-paragraph-number">4.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NC</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><a href="4-dtd.html#SP7" class="function-link"><span class="function-syntax">Deferrals::prepare_to_retrieve_callings_in_test_context</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="4-dtd.html#SP8" class="function-link"><span class="function-syntax">Deferrals::retrieve_callings_in_test_context</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">NC</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NC</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">go_up</span><span class="plain-syntax">) </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><a href="2-cc.html#SP5" class="function-link"><span class="function-syntax">CompileConditions::end</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4_1" class="paragraph-anchor"></a><b>&#167;4.1. </b>This is done purely for the sake of compiling tidier code: if \(\phi = \lnot(\psi)\)
then we defer \(\psi\) instead, negating the result of testing it.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">If the proposition is a negation, take care of that now</span><span class="named-paragraph-number">4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Propositions::is_a_group</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">NEGATION_OPEN_ATOM</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Propositions::remove_topmost_group</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">NOT_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">go_up</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-dtd.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2" class="paragraph-anchor"></a><b>&#167;4.2. </b>The first practical problem with deferrals is that the proposition is now
being tested in a different function, with its own stack frame, and that means
that it has no access to the local variables we can see here. Moreover, it
may not even be able to evaluate the term which the proposition is being
applied to. We are therefore going to need to call it as:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">f</span><span class="plain-syntax">(</span><span class="identifier-syntax">c_1</span><span class="plain-syntax">, ..., </span><span class="identifier-syntax">c_n</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary">where <span class="extract"><span class="extract-syntax">t</span></span> is the term, and <span class="extract"><span class="extract-syntax">c_1</span></span> to <span class="extract"><span class="extract-syntax">c_n</span></span> are any local variables which the
proposition mentions. (We want to avoid the misery of <a href="3-lp.html" class="internal">Local Parking</a>.)
Those passed values <span class="extract"><span class="extract-syntax">c_1</span></span>, ..., <span class="extract"><span class="extract-syntax">c_n</span></span> are called "cinders", and are covered
more fully in <a href="4-cad.html" class="internal">Cinders and Deferrals</a>. It is possible, of course, that <span class="extract"><span class="extract-syntax">n</span></span> is
zero, in which case there are no cinders at all.
</p>

<p class="commentary">Note that the term value <span class="extract"><span class="extract-syntax">t</span></span> &mdash; it it exists &mdash; becomes the initial value of
the local variable <span class="extract"><span class="extract-syntax">x</span></span> in the deferred function <span class="extract"><span class="extract-syntax">f</span></span>. This is correct, because
<span class="extract"><span class="extract-syntax">x</span></span> is the free variable in the proposition, so calling the function with <span class="extract"><span class="extract-syntax">t</span></span>
in the <span class="extract"><span class="extract-syntax">x</span></span> argument neatly effects a substitution of \(x = t\).
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Compile the call to the deferred function</span><span class="named-paragraph-number">4.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::call</span><span class="plain-syntax">(</span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ppd_iname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><a href="4-cad.html#SP4" class="function-link"><span class="function-syntax">Cinders::compile_cindered_values</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">substitution</span><span class="plain-syntax">) </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">substitution</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-dtd.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>The second practical problem concerns callings. If we compile:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">if</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">woman</span><span class="plain-syntax"> (</span><span class="identifier-syntax">called</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">moll</span><span class="plain-syntax">) </span><span class="identifier-syntax">has</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">weapon</span><span class="plain-syntax"> (</span><span class="identifier-syntax">called</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">gun</span><span class="plain-syntax">), ...</span>
</pre>
<p class="commentary">then we will need to defer the proposition, since it involves quantification
and therefore an implicit search loop. But it is supposed to set two local
variables, "moll" and "gun", with its findings; and they have to end up in
the caller's stack frame, not in the deferred function. Somehow, they need
to be return values of a sort from <span class="extract"><span class="extract-syntax">f</span></span>, but Inter's lack of memory access to
the call stack means that it is impossible for an Inter function to return
multiple values. What to do?
</p>

<p class="commentary">The answer is that <span class="extract"><span class="extract-syntax">f</span></span> copies these values onto a special array called the
"stash of callings". The very last thing that <span class="extract"><span class="extract-syntax">f</span></span> does before it returns
is to fill in this list; the very first thing we do on receiving that return
is to extract what we want from it. Because no other activity takes place in
between, there is no risk that some recursive use of propositions will
overwrite the list.
</p>

<p class="commentary">For example, our call might then become
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    (</span><span class="identifier-syntax">f</span><span class="plain-syntax">(</span><span class="identifier-syntax">c_1</span><span class="plain-syntax">, ..., </span><span class="identifier-syntax">c_n</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">t_2</span><span class="plain-syntax">=</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;0, </span><span class="identifier-syntax">t_3</span><span class="plain-syntax">=</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;1, </span><span class="identifier-syntax">true</span><span class="plain-syntax">))</span>
</pre>
<p class="commentary">which safely transfers the values to locals <span class="extract"><span class="extract-syntax">t_2</span></span> and <span class="extract"><span class="extract-syntax">t_3</span></span> of <span class="extract"><span class="extract-syntax">R</span></span>. Note that
Inter evaluates conditions joined by <span class="extract"><span class="extract-syntax">&amp;&amp;</span></span> from left to right, so we can be
certain that <span class="extract"><span class="extract-syntax">f</span></span> has been called and has returned <span class="extract"><span class="extract-syntax">true</span></span> before we get to the
setting of <span class="extract"><span class="extract-syntax">t_2</span></span> and <span class="extract"><span class="extract-syntax">t_3</span></span>.
</p>

<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>Here we find out what size of deferred list we will need:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::count_callings_in_condition</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">Deferrals::count_callings_in_condition</span></span>:<br/><a href="4-dtd.html#SP4">&#167;4</a>, <a href="4-dtd.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">calling_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TRAVERSE_VARIABLE</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TRAVERSE_PROPOSITION</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">, </span><span class="identifier-syntax">prop</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">CreationPredicates::is_calling_up_atom</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">calling_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">calling_count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>In both cases (a test, or something other), we will compile an expression
whose side-effects of evaluation will set the necessary calling locals. But
the details differ. Here <span class="extract"><span class="extract-syntax">f</span></span> is a test; <span class="extract"><span class="extract-syntax">g</span></span> is some other function returning
a value.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    (</span><span class="identifier-syntax">f</span><span class="plain-syntax">(</span><span class="identifier-syntax">c_1</span><span class="plain-syntax">, ..., </span><span class="identifier-syntax">c_n</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">t_2</span><span class="plain-syntax">=</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;0, </span><span class="identifier-syntax">t_3</span><span class="plain-syntax">=</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;1, </span><span class="identifier-syntax">true</span><span class="plain-syntax">))</span>
<span class="plain-syntax">    (</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;26 = </span><span class="identifier-syntax">g</span><span class="plain-syntax">(</span><span class="identifier-syntax">c_1</span><span class="plain-syntax">, ..., </span><span class="identifier-syntax">c_n</span><span class="plain-syntax">, </span><span class="identifier-syntax">t</span><span class="plain-syntax">), </span><span class="identifier-syntax">t_2</span><span class="plain-syntax">=</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;0, </span><span class="identifier-syntax">t_3</span><span class="plain-syntax">=</span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;1, </span><span class="identifier-syntax">stash</span><span class="plain-syntax">--&gt;26)</span>
</pre>
<p class="commentary">The return value of <span class="extract"><span class="extract-syntax">g</span></span>, which must emerge unscathed from this expression, is
stored temporarily in <span class="extract"><span class="extract-syntax">stash--&gt;26</span></span>.
</p>

<p class="commentary">The retrieval must be done in two stages. First, call this; then, in the
case which isn't <span class="extract"><span class="extract-syntax">as_test</span></span>, compile the return value of <span class="extract"><span class="extract-syntax">g</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::prepare_to_retrieve_callings_in_test_context</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">Deferrals::prepare_to_retrieve_callings_in_test_context</span></span>:<br/><a href="4-dtd.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="4-dtd.html#SP7" class="function-link"><span class="function-syntax">Deferrals::prepare_to_retrieve_callings</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::prepare_to_retrieve_callings_in_other_context</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">Deferrals::prepare_to_retrieve_callings_in_other_context</span></span>:<br/><a href="4-dtd.html#SP11">&#167;11</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="4-dtd.html#SP7" class="function-link"><span class="function-syntax">Deferrals::prepare_to_retrieve_callings</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::prepare_to_retrieve_callings</span><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">as_test</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">stash</span><span class="plain-syntax"> = </span><a href="3-lp.html#SP6" class="function-link"><span class="function-syntax">LocalParking::callings</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">CreationPredicates::contains_callings</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">as_test</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">); </span><span class="comment-syntax"> (1)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">); </span><span class="comment-syntax"> (2)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">STORE_BIP</span><span class="plain-syntax">); </span><span class="comment-syntax"> (3)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitCode::reference</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">LOOKUP_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">stash</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                            </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">(26);</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>Second, call one of the following functions:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::retrieve_callings_in_test_context</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">Deferrals::retrieve_callings_in_test_context</span></span>:<br/><a href="4-dtd.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">NC</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NC</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><a href="4-dtd.html#SP8" class="function-link"><span class="function-syntax">Deferrals::retrieve_callings_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">NC</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::retrieve_callings_in_other_context</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">Deferrals::retrieve_callings_in_other_context</span></span>:<br/><a href="4-dtd.html#SP11">&#167;11</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">NC</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP6" class="function-link"><span class="function-syntax">Deferrals::count_callings_in_condition</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">NC</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><a href="4-dtd.html#SP8" class="function-link"><span class="function-syntax">Deferrals::retrieve_callings_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">NC</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::retrieve_callings_inner</span><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">NC</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">as_test</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">as_test</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">(); </span><span class="comment-syntax"> closes (3)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">); </span><span class="comment-syntax"> (4)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="identifier-syntax">stash</span><span class="plain-syntax"> = </span><a href="3-lp.html#SP6" class="function-link"><span class="function-syntax">LocalParking::callings</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">calling_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">downs</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TRAVERSE_VARIABLE</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TRAVERSE_PROPOSITION</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">, </span><span class="identifier-syntax">prop</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">CreationPredicates::is_calling_up_atom</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="4-dtd.html#SP8_1" class="named-paragraph-link"><span class="named-paragraph">Retrieve this calling</span><span class="named-paragraph-number">8.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">downs</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) { </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">(); </span><span class="identifier-syntax">downs</span><span class="plain-syntax">--; }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">as_test</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::val_true</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">(); </span><span class="comment-syntax"> closes (1)</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">LOOKUP_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">stash</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">(26);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">(); </span><span class="comment-syntax"> closes (4)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">(); </span><span class="comment-syntax"> closes (2)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8_1" class="paragraph-anchor"></a><b>&#167;8.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Retrieve this calling</span><span class="named-paragraph-number">8.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">wording</span><span class="plain-syntax"> </span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CreationPredicates::get_calling_name</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">local_variable</span><span class="plain-syntax"> *</span><span class="identifier-syntax">local</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><a href="3-lv.html#SP20" class="function-link"><span class="function-syntax">LocalVariables::ensure_calling</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">W</span><span class="plain-syntax">, </span><span class="identifier-syntax">CreationPredicates::what_kind_of_calling</span><span class="plain-syntax">(</span><span class="identifier-syntax">atom</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">calling_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">calling_count</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">NC</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">downs</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">STORE_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">local_s</span><span class="plain-syntax"> = </span><a href="3-lv.html#SP1" class="function-link"><span class="function-syntax">LocalVariables::declare</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">local</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::ref_symbol</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">local_s</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">LOOKUP_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">stash</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) (</span><span class="identifier-syntax">calling_count</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">as_test</span><span class="plain-syntax">) </span><a href="2-cc.html#SP4" class="function-link"><span class="function-syntax">CompileConditions::add_calling</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">local</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-dtd.html#SP8">&#167;8</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>The following function can be used when:
</p>

<ul class="items"><li>&#9679; we want to force deferral in all cases, regardless of the proposition, and
</li><li>&#9679; we want to disallow all callings.
</li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_name</span><span class="plain-syntax"> *</span><span class="function-syntax">Deferrals::function_to_test_description</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::to_proposition</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">CreationPredicates::contains_callings</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_CantCallDeferredDescs</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="string-syntax">"'called' can't be used when testing a description"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"since it would make a name for something which existed only so temporarily "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"that it couldn't be used anywhere else."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP2" class="function-link"><span class="function-syntax">Deferrals::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">CONDITION_DEFER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ppd_iname</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Forcing with now, or deferring the force.</b>Again, we defer this if and only if there is quantification. But everything
is much easier here: we're in a void context, and we don't have callings.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_now_proposition</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_now_proposition</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Propositions::contains_quantifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP2" class="function-link"><span class="function-syntax">Deferrals::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">NOW_ASSERTION_DEFER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::call</span><span class="plain-syntax">(</span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ppd_iname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><a href="4-cad.html#SP4" class="function-link"><span class="function-syntax">Cinders::compile_cindered_values</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. Other uses.</b>Unlike "now" and testing, the other ways to use propositions &mdash; for example,
counting matches with "the number of ..." &mdash; can take a description which
might not be a constant. The following gives a general way to call a deferred
function for one of those other purposes, allowing for callings.
</p>

<p class="commentary">Callings can indeed occur, as in the example "a random person in a room (called
the haven)". <span class="extract"><span class="extract-syntax">RandomCalling</span></span> is a useful test case for this function.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::call_deferred_fn</span><button class="popup" onclick="togglePopup('usagePopup10')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup10">Usage of <span class="code-font"><span class="function-syntax">Deferrals::call_deferred_fn</span></span>:<br/><a href="4-dtd.html#SP15">&#167;15</a>, <a href="4-dtd.html#SP17">&#167;17</a>, <a href="4-dtd.html#SP18">&#167;18</a>, <a href="4-dtd.html#SP20">&#167;20</a>, <a href="4-dtd.html#SP21">&#167;21</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">reason</span><span class="plain-syntax">, </span><span class="identifier-syntax">general_pointer</span><span class="plain-syntax"> </span><span class="identifier-syntax">data</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP2" class="function-link"><span class="function-syntax">Deferrals::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">reason</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">defn_ref</span><span class="plain-syntax"> = </span><span class="identifier-syntax">data</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="4-dtd.html#SP7" class="function-link"><span class="function-syntax">Deferrals::prepare_to_retrieve_callings_in_other_context</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">arity</span><span class="plain-syntax"> = </span><a href="4-cad.html#SP3" class="function-link"><span class="function-syntax">Cinders::count</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">K</span><span class="plain-syntax">) </span><span class="identifier-syntax">arity</span><span class="plain-syntax"> = </span><span class="identifier-syntax">arity</span><span class="plain-syntax"> + </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">arity</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT0_BIP</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT1_BIP</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">: </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT2_BIP</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax">: </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT3_BIP</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">4</span><span class="plain-syntax">: </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT4_BIP</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"indirect function call with too many arguments"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ppd_iname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="4-cad.html#SP4" class="function-link"><span class="function-syntax">Cinders::compile_cindered_values</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><a href="3-sf.html#SP21" class="function-link"><span class="function-syntax">Frames::emit_new_local_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">RTKindIDs::emit_strong_ID_as_val</span><span class="plain-syntax">(</span><span class="identifier-syntax">Kinds::unary_construction_material</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="4-dtd.html#SP8" class="function-link"><span class="function-syntax">Deferrals::retrieve_callings_in_other_context</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Multipurpose descriptions.</b>Descriptions in the form \(\phi(x)\), where \(x\) is free, are also sometimes
converted into values &mdash; this is the kind of value "description". The
Inter representation is (the address of) a function <span class="extract"><span class="extract-syntax">D</span></span> which, in general,
performs task \(u\) on value \(v\) when called as <span class="extract"><span class="extract-syntax">D(u, v)</span></span>, where \(u\) is
expected to be one of the following values. (Note that \(v\) is only needed
in the first two cases.)
</p>

<p class="commentary">These numbers must be negative, since they need to be different from
every valid member of a quantifiable domain (objects, enumerated kinds, truth
states, times of day, and so on).
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">CONDITION_DUSAGE</span><span class="plain-syntax"> -1   </span><span class="comment-syntax"> return </span><span class="extract"><span class="extract-syntax">true</span></span><span class="comment-syntax"> iff </span>\(\phi(v)\)
<span class="definition-keyword">define</span> <span class="constant-syntax">LOOP_DOMAIN_DUSAGE</span><span class="plain-syntax"> -2 </span><span class="comment-syntax"> return the next </span>\(x\)<span class="comment-syntax"> after </span>\(v\)<span class="comment-syntax"> such that </span>\(\phi(x)\)
<span class="definition-keyword">define</span> <span class="constant-syntax">NUMBER_OF_DUSAGE</span><span class="plain-syntax"> -3   </span><span class="comment-syntax"> return the number of </span>\(w\)<span class="comment-syntax"> such that </span>\(\phi(w)\)
<span class="definition-keyword">define</span> <span class="constant-syntax">RANDOM_OF_DUSAGE</span><span class="plain-syntax"> -4   </span><span class="comment-syntax"> return a random </span>\(w\)<span class="comment-syntax"> such that </span>\(\phi(w)\)<span class="comment-syntax">, or 0 if none exists</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">TOTAL_DUSAGE</span><span class="plain-syntax"> -5       </span><span class="comment-syntax"> return the total value of a property among </span>\(w\)<span class="comment-syntax"> such that </span>\(\phi(w)\)
<span class="definition-keyword">define</span> <span class="constant-syntax">TOTAL_REAL_DUSAGE</span><span class="plain-syntax"> -6  </span><span class="comment-syntax"> the same, but using real arithmetic</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">EXTREMAL_DUSAGE</span><span class="plain-syntax"> -7    </span><span class="comment-syntax"> return the maximal property value among such </span>\(w\)
<span class="definition-keyword">define</span> <span class="constant-syntax">LIST_OF_DUSAGE</span><span class="plain-syntax"> -8     </span><span class="comment-syntax"> return the list of </span>\(w\)<span class="comment-syntax"> such that </span>\(\phi(w)\)
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>Multi-purpose description routines are pretty dandy, then, but they have
one big drawback: they can't be passed cinders, because they might be called
from absolutely anywhere. (And, once again, we are trying to avoid having to
capture local values as closures.) Hence the following:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::compile_multiple_use_proposition</span><button class="popup" onclick="togglePopup('usagePopup11')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup11">Usage of <span class="code-font"><span class="function-syntax">Deferrals::compile_multiple_use_proposition</span></span>:<br/>Compile Rvalues - <a href="2-cr.html#SP1_3">&#167;1.3</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> *</span><span class="identifier-syntax">VH</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">negate</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">quantifier</span><span class="plain-syntax"> *</span><span class="identifier-syntax">q</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Descriptions::get_quantifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">q</span><span class="plain-syntax"> == </span><span class="identifier-syntax">not_exists_quantifier</span><span class="plain-syntax">) </span><span class="identifier-syntax">negate</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">q</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">q</span><span class="plain-syntax"> != </span><span class="identifier-syntax">for_all_quantifier</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_spec</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">BelievedImpossible</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"In %1 you wrote the description '%2' in the context of a value, "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"but descriptions used that way are not allowed to talk about "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"quantities. For example, it's okay to write 'an even number' "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"as a description value, but not 'three numbers' or 'most numbers'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">negate</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Propositions::concatenate</span><span class="plain-syntax">(</span><span class="identifier-syntax">Atoms::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">NEGATION_OPEN_ATOM</span><span class="plain-syntax">), </span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Propositions::concatenate</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">Atoms::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">NEGATION_CLOSE_ATOM</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Propositions::concatenate</span><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">KindPredicates::new_atom</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">, </span><span class="identifier-syntax">Terms::new_variable</span><span class="plain-syntax">(0)), </span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TypecheckPropositions::type_check</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TypecheckPropositions::tc_no_problem_reporting</span><span class="plain-syntax">()) == </span><span class="identifier-syntax">NEVER_MATCH</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">example</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Binding::detect_locals</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">example</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOG</span><span class="plain-syntax">(</span><span class="string-syntax">"Offending proposition: $D\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::quote_wording</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">Node::get_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">example</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_LocalInDescription</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="string-syntax">"You wrote %1, but descriptions used as values are not allowed to "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"contain references to temporary values (defined by 'let', or by loops, "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"or existing only in certain rulebooks or actions, say) - unfortunately "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"'%2' is just such a temporary value. The problem is that it may well "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"not exist any more when the description needs to be used, in another "</span>
<span class="plain-syntax">            </span><span class="string-syntax">"time and another place."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">pcalc_prop_deferral</span><span class="plain-syntax"> *</span><span class="identifier-syntax">pdef</span><span class="plain-syntax"> = </span><a href="4-dtd.html#SP2" class="function-link"><span class="function-syntax">Deferrals::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">MULTIPURPOSE_DEFER</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">pdef</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">ppd_iname</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>Because multipurpose descriptions have this big drawback, we want to avoid them
if we possibly can. Fortunately something much simpler will often do. For example,
consider:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">(1) </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">number</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">members</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">S</span>
<span class="plain-syntax">(2) </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">number</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">closed</span><span class="plain-syntax"> </span><span class="identifier-syntax">doors</span>
</pre>
<p class="commentary">where S, in (1), is a description which appears as a parameter in a phrase.
In (1) we have no way of knowing what S might be, but we can safely assume
that it has been compiled as a multi-purpose description function <span class="extract"><span class="extract-syntax">D</span></span>, and
therefore compile the function call:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">D</span><span class="plain-syntax">(</span><span class="identifier-syntax">NUMBER_OF_DUSAGE</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary">But in case (2) it is sufficient to take \(\phi(x) = {\it door}(x)\land{\it closed}(x)\),
defer it to function <span class="extract"><span class="extract-syntax">f</span></span> with reason <span class="extract"><span class="extract-syntax">NUMBER_OF_DEFER</span></span>, and then compile just <span class="extract"><span class="extract-syntax">f()</span></span>
to perform the calculation. We never need a multi-purpose description routine for
\(\phi(x)\) because it only occurs in this one context.
</p>

<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>We now perform this trick for "number of":
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_number_of_matches</span><button class="popup" onclick="togglePopup('usagePopup12')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup12">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_number_of_matches</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-dtd.html#SP16" class="function-link"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT1_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="constant-syntax">NUMBER_OF_DUSAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-cp.html#SP7" class="function-link"><span class="function-syntax">CompilePropositions::verify_descriptive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"a number of things matching a description"</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-dtd.html#SP11" class="function-link"><span class="function-syntax">Deferrals::call_deferred_fn</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">NUMBER_OF_DEFER</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>By "variable", we actually mean any stored value:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span><button class="popup" onclick="togglePopup('usagePopup13')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup13">Usage of <span class="code-font"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></span>:<br/><a href="4-dtd.html#SP15">&#167;15</a>, <a href="4-dtd.html#SP17">&#167;17</a>, <a href="4-dtd.html#SP18">&#167;18</a>, <a href="4-dtd.html#SP20">&#167;20</a>, <a href="4-dtd.html#SP21">&#167;21</a>, <a href="4-dtd.html#SP22">&#167;22</a><br/>Compile Loops - <a href="4-cl.html#SP1_1">&#167;1.1</a>, <a href="4-cl.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Lvalues::is_lvalue</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Kinds::get_construct</span><span class="plain-syntax">(</span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) == </span><span class="identifier-syntax">CON_description</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. </b>And now for "list of":
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_list_of_matches</span><button class="popup" onclick="togglePopup('usagePopup14')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup14">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_list_of_matches</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-dtd.html#SP16" class="function-link"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::call</span><span class="plain-syntax">(</span><span class="identifier-syntax">Hierarchy::find</span><span class="plain-syntax">(</span><span class="identifier-syntax">LIST_OF_TY_DESC_HL</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><a href="3-sf.html#SP21" class="function-link"><span class="function-syntax">Frames::emit_new_local_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">RTKindIDs::emit_strong_ID_as_val</span><span class="plain-syntax">(</span><span class="identifier-syntax">Kinds::unary_construction_material</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-cp.html#SP7" class="function-link"><span class="function-syntax">CompilePropositions::verify_descriptive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"a list of things matching a description"</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-dtd.html#SP11" class="function-link"><span class="function-syntax">Deferrals::call_deferred_fn</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">LIST_OF_DEFER</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">, </span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP18" class="paragraph-anchor"></a><b>&#167;18. </b>And similarly for "a random ...":
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_random_match</span><button class="popup" onclick="togglePopup('usagePopup15')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup15">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_random_match</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-dtd.html#SP16" class="function-link"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT1_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="constant-syntax">RANDOM_OF_DUSAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-cp.html#SP7" class="function-link"><span class="function-syntax">CompilePropositions::verify_descriptive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"a random thing matching a description"</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Propositions::describes_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">K</span><span class="plain-syntax">) &amp;&amp; (</span><a href="4-dtd.html#SP19" class="function-link"><span class="function-syntax">Deferrals::has_finite_domain</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="4-dtd.html#SP18_1" class="named-paragraph-link"><span class="named-paragraph">Issue random impossible problem</span><span class="named-paragraph-number">18.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><a href="4-dtd.html#SP11" class="function-link"><span class="function-syntax">Deferrals::call_deferred_fn</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">RANDOM_OF_DEFER</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL_GENERAL_POINTER</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP18_1" class="paragraph-anchor"></a><b>&#167;18.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Issue random impossible problem</span><span class="named-paragraph-number">18.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">StandardProblems::sentence_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_RandomImpossible</span><span class="plain-syntax">),</span>
<span class="plain-syntax">        </span><span class="string-syntax">"this asks to find a random choice from a range which is too large or "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"impractical"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"so can't be done. For instance, 'a random person' is fine - it's clear "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"exactly who all the people are, and the supply is limited - but not 'a "</span>
<span class="plain-syntax">        </span><span class="string-syntax">"random text'."</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="4-dtd.html#SP18">&#167;18</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP19" class="paragraph-anchor"></a><b>&#167;19. </b>Some kinds are such that all legal values can efficiently be looped through
at run-time, some are not: we can sensibly loop over all scenes, but not
over all texts. We use the term "domain" to mean the set of values which
a loop traverses.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::has_finite_domain</span><button class="popup" onclick="togglePopup('usagePopup16')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup16">Usage of <span class="code-font"><span class="function-syntax">Deferrals::has_finite_domain</span></span>:<br/><a href="4-dtd.html#SP18">&#167;18</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">K</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Kinds::Behaviour::is_object</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Kinds::Behaviour::is_an_enumeration</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">LiteralPatterns::finite_extent</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">construct</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">loop_domain_schema</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP20" class="paragraph-anchor"></a><b>&#167;20. </b>And similarly for "total of":
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_total_of_matches</span><button class="popup" onclick="togglePopup('usagePopup17')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup17">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_total_of_matches</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">property</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prn</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">prn</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"total of on non-property"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ValueProperties::kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">prn</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">reason</span><span class="plain-syntax">, </span><span class="identifier-syntax">usage</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Kinds::FloatingPoint::uses_floating_point</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">reason</span><span class="plain-syntax"> = </span><span class="constant-syntax">TOTAL_REAL_DEFER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">usage</span><span class="plain-syntax"> = </span><span class="constant-syntax">TOTAL_REAL_DUSAGE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">reason</span><span class="plain-syntax"> = </span><span class="constant-syntax">TOTAL_DEFER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">usage</span><span class="plain-syntax"> = </span><span class="constant-syntax">TOTAL_DUSAGE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-dtd.html#SP16" class="function-link"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">STORE_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::ref_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Hierarchy::find</span><span class="plain-syntax">(</span><span class="identifier-syntax">PROPERTY_TO_BE_TOTALLED_HL</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">RTProperties::iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">prn</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT1_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">usage</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-cp.html#SP7" class="function-link"><span class="function-syntax">CompilePropositions::verify_descriptive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"a total property value for things matching a description"</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="4-dtd.html#SP11" class="function-link"><span class="function-syntax">Deferrals::call_deferred_fn</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="identifier-syntax">reason</span><span class="plain-syntax">, </span><span class="identifier-syntax">STORE_POINTER_property</span><span class="plain-syntax">(</span><span class="identifier-syntax">prn</span><span class="plain-syntax">), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP21" class="paragraph-anchor"></a><b>&#167;21. </b>And the extremal case is pretty well the same, too, with only some fuss over
identifying which superlative is meant. We get here from code like "let X be
the heaviest thing in the wooden box" where there has previously been a
definition of "heavy".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_extremal_match</span><button class="popup" onclick="togglePopup('usagePopup18')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup18">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_extremal_match</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">property</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prn</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">prn</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"extremal of on non-property"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-dtd.html#SP16" class="function-link"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">STORE_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::ref_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">Hierarchy::find</span><span class="plain-syntax">(</span><span class="identifier-syntax">PROPERTY_TO_BE_TOTALLED_HL</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::val_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">, </span><span class="identifier-syntax">RTProperties::iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">prn</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">SEQUENTIAL_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">STORE_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitCode::ref_iname</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_value</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">Hierarchy::find</span><span class="plain-syntax">(</span><span class="identifier-syntax">PROPERTY_LOOP_SIGN_HL</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">sign</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT1_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                    </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="constant-syntax">EXTREMAL_DUSAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">measurement_definition</span><span class="plain-syntax"> *</span><span class="identifier-syntax">mdef_found</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Measurements::retrieve</span><span class="plain-syntax">(</span><span class="identifier-syntax">prn</span><span class="plain-syntax">, </span><span class="identifier-syntax">sign</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">mdef_found</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">pcalc_prop</span><span class="plain-syntax"> *</span><span class="identifier-syntax">prop</span><span class="plain-syntax"> = </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="4-cp.html#SP7" class="function-link"><span class="function-syntax">CompilePropositions::verify_descriptive</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="string-syntax">"an extreme case of something matching a description"</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="4-dtd.html#SP11" class="function-link"><span class="function-syntax">Deferrals::call_deferred_fn</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">prop</span><span class="plain-syntax">, </span><span class="constant-syntax">EXTREMAL_DEFER</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">STORE_POINTER_measurement_definition</span><span class="plain-syntax">(</span><span class="identifier-syntax">mdef_found</span><span class="plain-syntax">), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP22" class="paragraph-anchor"></a><b>&#167;22. </b>Finally, the occasionally useful task of seeing if the current value of
the "substitution variable") is within the domain.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">Deferrals::defer_if_matches</span><button class="popup" onclick="togglePopup('usagePopup19')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup19">Usage of <span class="code-font"><span class="function-syntax">Deferrals::defer_if_matches</span></span>:<br/>Compile Propositions - <a href="4-cp.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">in</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="4-dtd.html#SP16" class="function-link"><span class="function-syntax">Deferrals::spec_is_variable_of_kind_description</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::inv</span><span class="plain-syntax">(</span><span class="identifier-syntax">INDIRECT2_BIP</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">            </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::val_number</span><span class="plain-syntax">((</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="constant-syntax">CONDITION_DUSAGE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">in</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><a href="4-cp.html#SP1" class="function-link"><span class="function-syntax">CompilePropositions::to_test_as_condition</span></a><span class="plain-syntax">(</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">in</span><span class="plain-syntax">, </span><span class="identifier-syntax">SentencePropositions::from_spec</span><span class="plain-syntax">(</span><span class="identifier-syntax">spec</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="4-cl.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-im.html">1</a></li><li class="progresschapter"><a href="2-cv.html">2</a></li><li class="progresschapter"><a href="3-sf.html">3</a></li><li class="progresscurrentchapter">4</li><li class="progresssection"><a href="4-cs.html">cs</a></li><li class="progresssection"><a href="4-ca.html">ca</a></li><li class="progresssection"><a href="4-cp.html">cp</a></li><li class="progresssection"><a href="4-cl.html">cl</a></li><li class="progresscurrent">dtd</li><li class="progresssection"><a href="4-cad.html">cad</a></li><li class="progresssection"><a href="4-cdp.html">cdp</a></li><li class="progresschapter"><a href="5-cbal.html">5</a></li><li class="progressnext"><a href="4-cad.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

